package com.guomao.service;

import com.guomao.dao.BookDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

@Service
//@Transactional
public class BookService {

    @Autowired
    private BookDao bookDao;


    //    @Transactional(readOnly = true,)
//    @Transactional(isolation = Isolation.REPEATABLE_READ)
//    @Transactional(timeout = 3000)
    @Transactional
    public void check(String name, String id) {
        //1 划扣余额
        int price = bookDao.getPrice(id);
        bookDao.updateBalance(name, price);

//        System.out.println(10 / 0);
        //2 更新库存
        bookDao.updateStock(id);
    }
}
